package net.lzzy.practices.repositories;

import net.lzzy.practices.entities.Course;
import net.lzzy.practices.entities.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface CourseRepository extends JpaRepository<Course, UUID> {
    /**
     * 获取所有的选修课程
     * @return
     */
    List<Course> findAllByOrderByUpdateTimeDesc();

    /**
     * 获取所有开放的选修课程
     * @param open
     * @return
     */
    List<Course> findCoursesByOpenEqualsOrderByUpdateTimeDesc(boolean open);

    /**
     * 获取所有课程的分页
     * @param pageable
     * @return
     */
    List<Course> findAllByOrderByUpdateTimeDesc(Pageable pageable);

    /**
     * 获取所有课程的分页
     * @param pageable
     * @param open
     * @return
     */
    List<Course> findCoursesByOpenEqualsOrderByUpdateTimeDesc(Pageable pageable, boolean open);
    Integer countAllBy();
    Integer countCoursesByOpenEquals(boolean open);
    List<Course> findCoursesByTeacherIdEqualsOrderByCreateTimeDesc(UUID id);
    List<Course> findCoursesByStudentsContainsAndOpenOrderByUpdateTimeDesc(User student, boolean open);
}
